//
//  HNSH_AccountEditHeaderView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/28.
//

#import "HNSH_AccountEditHeaderView.h"

@interface HNSH_AccountEditHeaderView ()
/* headerImgV */
@property (nonatomic, strong) UIImageView *headerImgV;
/* nameLabel */
@property (nonatomic, strong) UILabel *nameLabel;
/* iconImgV */
@property (nonatomic, strong) UIImageView *iconImgV;
@end

@implementation HNSH_AccountEditHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)setUserInfo:(ST_UserInfo *)userInfo {
    [self.headerImgV sd_setImageWithURL:[NSURL URLWithString:userInfo.avatar_url] placeholderImage:[UIImage imageNamed:@"base_user_header_icon"]];
    self.nameLabel.text = userInfo.nickname;
}

- (void)setHeaderUrl:(NSString *)headerUrl {
    _headerUrl = headerUrl;
    [self.headerImgV sd_setImageWithURL:[NSURL URLWithString:headerUrl]];
}

- (void)configUI {
    [self addSubview:self.headerImgV];
    [self addSubview:self.nameLabel];
    [self addSubview:self.iconImgV];
    
    [self.headerImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.mas_equalTo(32);
        make.width.height.mas_equalTo(100);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.headerImgV.mas_bottom).offset(13);
        make.height.mas_equalTo(33);
    }];
    
    [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.headerImgV.mas_right).offset(10);
        make.bottom.equalTo(self.headerImgV.mas_bottom).offset(10);
        make.width.height.mas_equalTo(34);
    }];
    
    UIView *lineView = [[UIView alloc]init];
    lineView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F6"];
    [self addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(38);
        make.right.mas_equalTo(-38);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1);
    }];
}

#pragma mark lazy
- (UIImageView *)headerImgV {
    if (!_headerImgV) {
        _headerImgV = [[UIImageView alloc]init];
        _headerImgV.contentMode = UIViewContentModeScaleAspectFill;
        _headerImgV.layer.cornerRadius = 50;
        _headerImgV.layer.masksToBounds = YES;
        _headerImgV.userInteractionEnabled = YES;
        WeakSelf(weakSelf);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithActionBlock:^(id  _Nonnull sender) {
            if (weakSelf.headerBlock) {
                weakSelf.headerBlock();
            }
        }];
        [_headerImgV addGestureRecognizer:tap];
    }
    return _headerImgV;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"";
        _nameLabel.textColor = [UIColor appBlackLabelColor];
        _nameLabel.font = [UIFont boldSystemFontOfSize:24];
    }
    return _nameLabel;
}

- (UIImageView *)iconImgV {
    if (!_iconImgV) {
        _iconImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_account_edit_header"]];
        _iconImgV.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _iconImgV;
}

@end
